﻿using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using RouterControl.IO;
using System.Diagnostics;
using System.Windows.Forms;

namespace RouterControl.Diag
{
	internal abstract class Diagnosis
	{
        public enum DiagResult
        {
            Success,
            Failure,
            Abort       // skips all following tests
        }

		protected readonly ILog _log;
		protected List<DiagFile> _diagFiles = new List<DiagFile>();		// list of files added to the zip file

		public IList<DiagFile> DiagnosticFiles
		{
			get { return _diagFiles.AsReadOnly(); }
		}

		public ListViewItem ListItem
		{
			get;
			private set;
		}

        public virtual int ProgressWeight
        {
            get { return 100; }
        }

        public abstract DiagResult Run();

		protected Diagnosis(string title)
		{
            _log = LogManager.GetLogger(GetType());

			this.ListItem = new ListViewItem()
			{
				Text = title,
				ImageIndex = 0
			};

		}

		protected void LogProperties(object o)
		{
			if (o == null)
				throw new ArgumentNullException("o");

			foreach (var p in o.GetType().GetProperties())
				_log.DebugFormat("... {0} = \"{1}\"", p.Name, p.GetValue(o, null));
		}

	}
}
